home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d16 / nodee1.arc / SOURCE.ARC / NODEE.CPP < prev    next >
C/C++ Source or Header  |  1991-09-01  |  12KB  |  556 lines

  1. /*  No control D
  2. NOCTRL.CPP
  3.  
  4. written by James D. Rudnicki
  5.  
  6. written in  C++ Version */
  7.  
  8. // Access the libraries needed
  9.  
  10.     #if !defined(__WINDOWS_H)
  11.         #include <windows.h>
  12.     #endif
  13.  
  14.     #include <stdlib.h>
  15.     #include <stdio.h>
  16.     #include <iostream.h>
  17.     #include <fstream.h>
  18.  
  19.     #ifndef __STRING_H
  20.         #include <string.h>
  21.     #endif
  22.  
  23. /* Attach a debug header - to remove debug code compile
  24. with compiler switch -D NDEBUG  */
  25.  
  26. //    #include "debug.h"
  27.  
  28. // symbol tables
  29.     #ifndef __NOD1_H
  30.     #include "nod1.h"
  31.     #endif
  32.  
  33.  
  34. /*-------------------------------------------
  35. All dialog boxes are included from a separate file.
  36. An independent symbol table is used. */
  37.  
  38.     #ifndef __CLASSWIN_H
  39.         #include "classwin.h"
  40.     #endif
  41.     #ifndef _NODDLGS_H
  42.         #include "noddlgs.h"
  43.     #endif
  44.     #ifndef __NODCHILD_H
  45.         #include "nodchild.h"
  46.     #endif
  47.  
  48.  
  49. /*------------------------------------------------------------
  50.  The Main Window class
  51.  
  52. NoDWindow - constructor reads the private profile strings
  53.  
  54. ~NoDWindow - writes out the private profile strings
  55.  
  56. */
  57.  
  58.     #pragma arsused
  59.  
  60.     class NoDWindow : public Window
  61.     {
  62.     public:
  63.         NoDWindow();
  64.         ~NoDWindow();
  65.  
  66.     protected:
  67.         virtual LONG dispatch(WORD,WORD,LONG);
  68.         virtual BOOL registerClass();
  69.         virtual BOOL createWindow();
  70.  
  71.     private:
  72.  
  73. /* defaults */
  74.  
  75.         char szDefDir[MAXPATH];
  76.         BOOL bOneClick;
  77.         BOOL bInstantStrip;
  78.         BOOL bUseFileMask;
  79.         BOOL bFirstRun;
  80.         char szFileMask[MAXFULLFILE];
  81.  
  82. // member data
  83.  
  84.         static char szClassName[14];
  85.         char szBuffer[MAXPATH];
  86.         char szFile[MAXPATH];
  87.         char szCleanFile[MAXPATH];
  88.         int cxChar,cxCaps,cyChar;
  89.         int cxClient,cyClient,cxBit,cyBit;
  90.         BOOL bValidFile;
  91.         HMENU hMenu;
  92.         OFSTRUCT ofs;
  93.  
  94. // these member functions process commands
  95.  
  96.         BOOL processMenuCommand(WORD,long);
  97.         BOOL processChildCommand(WORD,long);
  98.  
  99. // these member functions are the workers
  100.  
  101.         void flash(BOOL);
  102.  
  103.         void helpAboutBox(void);
  104.         void helpWroteBox(void);
  105.         void paint( void );
  106.         int strip();
  107.         BOOL test();
  108.  
  109.  
  110. // child windows are declared here and created later
  111.  
  112.         GoButton gb;
  113.         FirstLine fl;
  114.         FileFinder childFileList;
  115.         DBox dbox;
  116.  
  117.  
  118.     };
  119.  
  120.  
  121.     char NoDWindow::szClassName[] = "No ^D !";
  122.  
  123. /* The constructor and destructors read and write the default
  124. values to the private initialization file */
  125.  
  126.     NoDWindow::NoDWindow()
  127.     {
  128.         if    (GetPrivateProfileString
  129.                 (INISECTION,"Mask","",szFileMask,MAXFULLFILE,PRIVATEINI) != 0)
  130.         {
  131.             bFirstRun=FALSE;
  132.  
  133.             GetPrivateProfileString
  134.                 (INISECTION,"DefDir","",szDefDir,MAXPATH,PRIVATEINI);
  135.  
  136.             bOneClick =
  137.                 (GetPrivateProfileInt(INISECTION,"OneClick",1,PRIVATEINI) == 0)
  138.                 ? FALSE : TRUE;
  139.  
  140.             bInstantStrip =
  141.                 (GetPrivateProfileInt(INISECTION,"InstantStrip",1,PRIVATEINI) == 0)
  142.                  ? FALSE : TRUE;
  143.  
  144.             bUseFileMask =
  145.                 (GetPrivateProfileInt(INISECTION,"UseMask",1,PRIVATEINI) == 0)
  146.                  ? FALSE : TRUE;
  147.  
  148.         }
  149.         else
  150.         {
  151.             bFirstRun=TRUE;
  152.             strcpy(szFileMask,"*.PS");
  153.             bOneClick=FALSE;
  154.             bInstantStrip=FALSE;
  155.             bUseFileMask=FALSE;
  156.         }
  157.     }
  158.  
  159.     NoDWindow::~NoDWindow()
  160.     {
  161.         WritePrivateProfileString
  162.             (INISECTION,"Mask",szFileMask,PRIVATEINI);
  163.  
  164.         WritePrivateProfileString
  165.             (INISECTION,"DefDir",szDefDir,PRIVATEINI);
  166.  
  167.         WritePrivateProfileString
  168.             (INISECTION,"OneClick",bOneClick ? "1" : "0",PRIVATEINI);
  169.  
  170.         WritePrivateProfileString
  171.             (INISECTION,"InstantStrip",bInstantStrip ? "1":"0",PRIVATEINI);
  172.  
  173.         WritePrivateProfileString
  174.             (INISECTION,"UseMask",bUseFileMask ? "1" : "0",PRIVATEINI);
  175.     }
  176.  
  177. /* Define the members of NoDWindow */
  178.  
  179.  
  180.         BOOL NoDWindow::registerClass( void )
  181.         {
  182.             WNDCLASS wc;
  183.  
  184.             wc.style         = CS_HREDRAW | CS_VREDRAW;
  185.             wc.lpfnWndProc   = &Window::wndProc;
  186.             wc.cbClsExtra    = 0;
  187.             wc.cbWndExtra    = 0;
  188.             wc.hInstance     = hInst;
  189.             wc.hIcon         = LoadIcon( hInst, "nodee" );
  190.             wc.hCursor       = LoadCursor( NULL, IDC_ARROW );
  191.             wc.hbrBackground = GetStockObject( WHITE_BRUSH );
  192.             wc.lpszMenuName  = "MENU";
  193.             wc.lpszClassName = (LPSTR)szClassName;
  194.  
  195.             return RegisterClass( &wc ) ;
  196.         }
  197.  
  198.  
  199.         BOOL NoDWindow::createWindow( void )
  200.         {
  201.             HDC hdc;
  202.             TEXTMETRIC tm;
  203.             int cx,cy;
  204.             cx=GetSystemMetrics(SM_CXSCREEN);
  205.             cy=GetSystemMetrics(SM_CYSCREEN);
  206.  
  207.             hWindow = CreateWindow
  208.                 ( szClassName,
  209.                     szClassName,
  210.                     WS_OVERLAPPED|WS_SYSMENU|WS_CAPTION|
  211.                     WS_DLGFRAME|WS_VISIBLE|WS_MINIMIZEBOX,
  212.                     CW_USEDEFAULT,CW_USEDEFAULT,
  213.                     3*cx/4,3*cy/4,
  214.                     NULL,
  215.                     NULL,
  216.                     hInst,
  217.                     NULL);
  218.  
  219.             if ( hWindow==0 )    return( FALSE );
  220.             insert();
  221.  
  222. /* the window handle is now valid - initialize global parameters */
  223.  
  224.             hdc=GetDC(hWindow);
  225.             SelectObject(hdc,GetStockObject(SYSTEM_FONT));
  226.             GetTextMetrics(hdc,&tm);
  227.             cxChar=tm.tmAveCharWidth;
  228.             cyChar=tm.tmHeight+tm.tmExternalLeading;
  229.             cxCaps=(tm.tmPitchAndFamily & 1 ? 3 : 2) * cxChar/2;
  230.             ReleaseDC(hWindow,hdc);
  231.  
  232.             hMenu=GetMenu(hWindow);
  233.  
  234. /* create child windows */
  235.  
  236.             dbox.create(hWindow);
  237.             gb.create(hWindow);
  238.             fl.create(hWindow);
  239.             fl.set(szCleanFile);
  240.  
  241.             childFileList.mask(bUseFileMask ? szFileMask : "*.*" );
  242.             childFileList.create(hWindow);
  243.  
  244. /* initialize the menu states and child windows */
  245.  
  246.             SetClassWord
  247.                 (childFileList.FileList::getHandle(), GCW_HCURSOR,    bInstantStrip ?
  248.                 LoadCursor(hInst,NODCURSOR):LoadCursor(NULL,IDC_ARROW) );
  249.  
  250.             CheckMenuItem(hMenu,IDM_OPT1A,bInstantStrip ? MF_CHECKED:MF_UNCHECKED);
  251.             CheckMenuItem(hMenu,IDM_OPT1B,bOneClick ? MF_CHECKED:MF_UNCHECKED);
  252.             CheckMenuItem(hMenu,IDM_OPT1C,bUseFileMask ? MF_CHECKED:MF_UNCHECKED);
  253.  
  254.  
  255.             if (_fstrlen(WinBase::cmd)==0)
  256.                 strcpy(szCleanFile,"nothing selected");
  257.             else
  258.                 strcpy(szCleanFile,(char *)WinBase::cmd);
  259.  
  260.             test();
  261.  
  262.             ShowWindow(hWindow,show );
  263.             UpdateWindow(hWindow);
  264.  
  265.             if (bFirstRun)
  266.                 WinHelp(hWindow,HELPFILE,HELP_INDEX,NULL);
  267.  
  268.             return TRUE;
  269.         }
  270.  
  271.  
  272.     void NoDWindow::paint( void )
  273.     {
  274.         PAINTSTRUCT ps;
  275.         HDC hdc;
  276.         RECT rect;
  277.         hdc=BeginPaint( hWindow, &ps );
  278.         TextOut(hdc,cxChar,cyChar,
  279.             "Stripping ^D from:",18);
  280.         EndPaint( hWindow, &ps );
  281.     }
  282.  
  283.  
  284.     int NoDWindow::strip()
  285.     {
  286.         char str[80];
  287.         int j,i;
  288.         OFSTRUCT o;
  289.  
  290.         OpenFile((LPSTR)szCleanFile,&o,OF_READ|OF_EXIST);
  291.  
  292.         ifstream io((char *)o.szPathName);
  293.         if ( !io )
  294.         {
  295.             MessageBox(hWindow,"File did not open",
  296.                 (LPSTR)szCleanFile,MB_ICONSTOP|MB_OK);
  297.             return 0;
  298.         }
  299.         else
  300.         {
  301.             io.getline(str,80);
  302.             io.close();
  303.             if (strchr(str,4) != NULL);
  304.             {
  305.                 fstream io((char *)o.szPathName,ios::in|ios::out);
  306.                 io.seekp(0,ios::beg);
  307.  
  308.                 j=strlen(str);
  309.                 for(i=0;i<j;i++)
  310.                     if ( str[i] != 0x4)
  311.                         io.put(str[i]);
  312.                 io.close();
  313.  
  314.                 if (! bInstantStrip)
  315.                 MessageBox(hWindow,"File cleaned",
  316.                     (LPSTR)szCleanFile,MB_ICONEXCLAMATION|MB_OK);
  317.  
  318.                 dbox.unset();
  319.                 EnableWindow(gb.getHandle(),FALSE);
  320.                 SetFocus(hWindow);
  321.                 return 1;
  322.             }
  323.         }
  324.         return 0;
  325.     }
  326.  
  327.     BOOL NoDWindow::test()
  328.     {
  329.         char str[80];
  330.         char str2[80];
  331.         BOOL i,j;
  332.         OFSTRUCT o;
  333.  
  334.         OpenFile((LPSTR)szCleanFile,&o,OF_READ|OF_EXIST);
  335.  
  336.         ifstream io((char *)o.szPathName);
  337.         if ( io )
  338.         {
  339.             io.getline(str,80);
  340.             io.close();
  341.             i=(strstr(str,SZPOSTSCRIPT) != (char*)NULL) ;
  342.             j=(strchr(str,4) != (char *)NULL);
  343.             if (i && j)
  344.             {
  345.                 dbox.set();
  346.                 EnableWindow(gb.getHandle(),TRUE);
  347.                 SetFocus(gb.getHandle());
  348.                 return TRUE;
  349.             }
  350.         }
  351.         dbox.unset();
  352.         EnableWindow(gb.getHandle(),FALSE);
  353.         SetFocus(hWindow);
  354.         return FALSE;
  355.     }
  356.  
  357.  
  358.     void NoDWindow::helpAboutBox()
  359.     {
  360.         AboutBox x(hWindow);
  361.         x.run();
  362.     }
  363.  
  364.     BOOL NoDWindow::processMenuCommand(WORD wParam, long lParam)
  365.     {
  366.         switch(wParam)
  367.         {
  368.         case IDM_OPT1A:
  369.             bInstantStrip=!bInstantStrip;
  370.             if (bInstantStrip)
  371.             {
  372.                 CheckMenuItem(hMenu,IDM_OPT1A,MF_CHECKED);
  373.                 SetClassWord
  374.                     (childFileList.FileList::getHandle(),GCW_HCURSOR,LoadCursor(hInst,NODCURSOR));
  375.             }
  376.             else
  377.             {
  378.                 CheckMenuItem(hMenu,IDM_OPT1A,MF_UNCHECKED);
  379.                 SetClassWord
  380.                     (childFileList.FileList::getHandle(),GCW_HCURSOR,LoadCursor(NULL,IDC_ARROW));
  381.             }
  382.             if (bInstantStrip && test())
  383.                 strip();
  384.             return TRUE;
  385.  
  386.         case IDM_OPT1B:
  387.             CheckMenuItem(hMenu,IDM_OPT1B,(bOneClick = !bOneClick) ?
  388.                 MF_CHECKED:MF_UNCHECKED);
  389.             return TRUE;
  390.  
  391.         case IDM_OPT1C:
  392.             CheckMenuItem(hMenu,IDM_OPT1C,(bUseFileMask = !bUseFileMask) ?
  393.                 MF_CHECKED:MF_UNCHECKED);
  394.             childFileList.mask(bUseFileMask ? szFileMask : "*.*" );
  395.             childFileList.reset();
  396.             return TRUE;
  397.  
  398.         case IDM_H1B:
  399.             helpAboutBox();
  400.             return TRUE;
  401.  
  402.         case IDM_H1C:
  403.             WinHelp(hWindow,HELPFILE,HELP_INDEX,NULL);
  404.             return TRUE;
  405.  
  406.         default:
  407.             return FALSE;
  408.         }
  409.     }
  410.  
  411.     BOOL NoDWindow::processChildCommand(WORD wParam, long lParam)
  412.     {
  413.         int i;
  414.         switch(wParam)
  415.         {
  416.         case MYCW_ICKBUTTON:
  417.         case MYCW_GOBUTTON:
  418.             strip();
  419.             return TRUE;
  420.  
  421.         case MYCW_FILELIST:
  422.             if ( (HIWORD (lParam) == LBN_DBLCLK ) ||
  423.                      bOneClick && (HIWORD (lParam) == LBN_SELCHANGE) )
  424.             {
  425.                 if (childFileList.fileClick())
  426.                 {
  427.                     if (childFileList.validFile())
  428.                     {
  429.                         strcpy(szCleanFile,childFileList.getFile());
  430.                         fl.set(szCleanFile);
  431.                         if (test() && bInstantStrip)
  432.                             strip();
  433.                     }
  434.                     return TRUE;
  435.                 }
  436.             }
  437.             return FALSE;
  438.  
  439.         case MYCW_DIRLIST:
  440.         case MYCW_DIRFIELD:
  441.             if ( (HIWORD (lParam) == LBN_DBLCLK ) ||
  442.                      bOneClick && (HIWORD (lParam) == LBN_SELCHANGE) )
  443.             {
  444.                 if (childFileList.dirClick())
  445.                 {
  446.                     fl.set("none selected");
  447.                     return TRUE;
  448.                     dbox.unset();
  449.                     EnableWindow(gb.getHandle(),FALSE);
  450.                     SetFocus(hWindow);
  451.                 }
  452.             }
  453.             return FALSE;
  454.  
  455.         }
  456.         return FALSE;
  457.     }
  458.  
  459. /* This is the big switch
  460.  
  461. NOTE: Do no process the WM_CREATE message here.
  462. Upon the WM_CREATE message, the handle hWnd is not yet
  463. valid.  Do not use the handle until the CreateWindow call in the
  464. constructor has completed execution.  Any code which need be executed
  465. on creation can be placed in the create function .
  466.  
  467. This differs from normal C programs.  When CreateWindow sends the WM_CREATE
  468. message, the window handle is also passed to WndProc.  Thereby, the
  469. first processing of WM_CREATE will have access to the handle. */
  470.  
  471.     long NoDWindow::dispatch( WORD iMessage, WORD wParam, LONG lParam )
  472.     {
  473.         switch (iMessage)
  474.         {
  475.  
  476.             case WM_PAINT:
  477.                 paint();
  478.                 return 0;
  479.  
  480.             case WM_SIZE:
  481.                 cxClient=LOWORD(lParam);
  482.                 cyClient=HIWORD(lParam);
  483.                 return 0;
  484.  
  485. /* commands are send to the Menu processor, and then the Child processor
  486. If neither of these routines indicates it handled the command, the
  487. default procedure will be called. */
  488.  
  489.             case WM_COMMAND:
  490.                 if(processMenuCommand(wParam,lParam))
  491.                     return 0;
  492.                 if(processChildCommand(wParam,lParam))
  493.                     return 0;
  494.                 break;
  495.  
  496. /* catch this message - The file list should be updated when the
  497. program has not been active.  Also set the cursor back to normal
  498. when leaving this app.  Otherwise, the cursor will appear altered over
  499. ANY window's list box. */
  500.  
  501.             case WM_ACTIVATEAPP:
  502.                 if(wParam != 0)
  503.                 {
  504.                     childFileList.reset();
  505.                     SetClassWord
  506.                         (childFileList.FileList::getHandle(),GCW_HCURSOR,bInstantStrip?
  507.                         LoadCursor(hInst,NODCURSOR):LoadCursor(NULL,IDC_ARROW) );
  508.                 }
  509.                 else
  510.                 {
  511.                     SetClassWord
  512.                         (childFileList.FileList::getHandle(), GCW_HCURSOR,
  513.                          LoadCursor(NULL,IDC_ARROW) );
  514.                 }
  515.  
  516.                 return 0;
  517.  
  518. /* When leaving, make sure to set the cursor back to normal and
  519. tell help to quit.*/
  520.  
  521.             case WM_DESTROY:
  522.                 SetClassWord
  523.                 (childFileList.FileList::getHandle(), GCW_HCURSOR,
  524.                  LoadCursor(NULL,IDC_ARROW) );
  525.                 WinHelp(hWindow,HELPFILE,HELP_QUIT,NULL);
  526.  
  527.                 PostQuitMessage( 0 );
  528.                 return 0;
  529.  
  530.         }
  531.  
  532.         return Window::dispatch( iMessage, wParam, lParam );
  533.  
  534.     }
  535.  
  536.  
  537. /*-------------------------------------------------------------
  538. This is the end of the Main program.  The following procedures are
  539. called from Windows directly */
  540.  
  541.  
  542.  
  543.     int PASCAL WinMain
  544.         (HANDLE hInstance,HANDLE hPrev,LPSTR lpszCmdLine,int nCmdShow)
  545.     {
  546.         WinBase::hInst = hInstance;
  547.         WinBase::hPrevInst = hPrev;
  548.         WinBase::cmd = lpszCmdLine;
  549.         WinBase::show = nCmdShow;
  550.  
  551.         NoDWindow A;
  552.         A.create();
  553.         return A.run();
  554.     }
  555.  
  556.